﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace HeliGame
{
    struct Light
    {
        public Vector3 position;
        public Color color;

        public TextureCube cubicShadowMap;
        public Matrix[] viewProjections;

        public void CalcViewProjectionMatrices()
        {
            viewProjections = new Matrix[6];
            int i;
            for (i = 0; i < 6; i++)
            {
                switch ((CubeMapFace)i)
                {
                    case CubeMapFace.NegativeX:
                        viewProjections[i] = Matrix.CreateLookAt(position, position + Vector3.Left, Vector3.Up);
                        break;
                    case CubeMapFace.NegativeY:
                        viewProjections[i] = Matrix.CreateLookAt(position, position + Vector3.Down, Vector3.Forward);
                        
                        break;
                    case CubeMapFace.NegativeZ:
                        viewProjections[i] = Matrix.CreateLookAt(position, position + Vector3.Forward, Vector3.Up);
                        break;

                    case CubeMapFace.PositiveX:
                        viewProjections[i] = Matrix.CreateLookAt(position, position + Vector3.Right, Vector3.Up);
                        break;
                    case CubeMapFace.PositiveY:
                        viewProjections[i] = Matrix.CreateLookAt(position, position + Vector3.Up, Vector3.Backward);
                        break;
                    case CubeMapFace.PositiveZ:
                        viewProjections[i] = Matrix.CreateLookAt(position, position + Vector3.Backward, Vector3.Up);
                        break;
                }

                
            }
            for (i = 0; i < 6; i++)
            {
                //viewProjections[i] = Matrix.CreateLookAt(position, Vector3.Right, Vector3.Up);
                viewProjections[i] = viewProjections[i] * 
                    Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 1, 0.1f, 40.0f);
            }
        }
    }
}
